package generators;

public class GenerateAll {
	static String startingDir = null;
	public static void main(String[] args) {
		startingDir = (args != null && args.length > 0) ? args[0] : ".";
		
		int count = 8;
		generate(0, count, new FunctionGeneratorWriter(), "Fun");
		generate(0, count, new ListFunctionGeneratorWriter(), "ListFun");
		generate(0, count, new TSListFunctionGeneratorWriter(), "ListFunTS");
		generate(1, count, new TupleGeneratorWriter(), "Tuple");
		
		// one offs
		generate(count, new MemoizingGeneratorWriter(), "Memoize");
		generate(count, new UnmemoizingGeneratorWriter(), "Unmemoize");
		generate(count, new MatchingGeneratorWriter(), "Match");
		generate(count, new TupleMessagingGeneratorWriter(), "TupleMessaging");
		generate(count, new SubjectMessagingGeneratorWriter(), "SubjectMessaging");
	}

	private static void generate(int i, GeneratorBase generator, String what){
		System.out.println("generating "+what+i);
		// output to the generated dir
		Object result = generator._generate( new String[]{String.valueOf(i),"jsa:o="+startingDir+"/generated"}, false );
	    int exitvalue = 0;
	    if( result instanceof Integer ) {
	      exitvalue = ((Integer)result).intValue();
	    }
	    if (exitvalue!=0){
	    	System.err.println("Exited with "+exitvalue);
	    	return;
	    }
	}
	
	private static void generate(int start, int count, GeneratorBase generator, String what) {
		for(int i=start; i<count; i++){
			generate(i, generator, what);
		}
	}
}
